package com.yungu.swift.admin.route.finance;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.PageVo;
import com.yungu.swift.system.finance.model.dto.FinanceAccountSettlementDto;
import com.yungu.swift.system.finance.model.param.AdminAccountPageParam;
import com.yungu.swift.system.finance.model.param.AdminAccountSettlementPageParam;
import com.yungu.swift.system.finance.service.FinanceAccountSettlementService;
import com.yungu.swift.system.sys.model.vo.SysAgentAccountVo;
import com.yungu.swift.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/admin/v1/finance/balance/settlement")
@Api(value = "【财务管理】", tags = "账户结算")
public class AccountSettlementAdmin {

    @Reference
    private FinanceAccountSettlementService financeAccountSettlementService;

    @RequestMapping(value = "/queryPage", method = RequestMethod.POST)
    @ApiOperation(value = "账户结算查询", httpMethod = "POST")
    public ResponseData<PageVo<FinanceAccountSettlementDto>> queryPage(@RequestBody AdminAccountSettlementPageParam accountPageParam) {
        if(StringUtils.isEmpty(accountPageParam.getAccountUuid())){
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE,"参数错误");
        }
        return financeAccountSettlementService.queryPageVo(accountPageParam);
    }

    @RequestMapping(value = "/handle", method = RequestMethod.POST)
    @ApiOperation(value = "结算", httpMethod = "POST")
    public ResponseData<Boolean> queryPage(@RequestBody Map<String,Object> parmMap) {
        Object uuid = parmMap.get("uuid");
        if(uuid==null){
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE,"参数错误");
        }
        return financeAccountSettlementService.settlementHandle(uuid.toString());
    }

    @RequestMapping(value = "/statistics", method = RequestMethod.POST)
    @ApiOperation(value = "统计", httpMethod = "POST")
    public ResponseData<Map<String,Object>> statistics(@RequestBody Map<String,Object> parmMap) {
        Object accountUuid = parmMap.get("accountUuid");
        if(accountUuid==null){
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE,"参数错误");
        }
        return financeAccountSettlementService.statistics(accountUuid.toString());
    }
}
